package com.example.lianxi222.login;

import androidx.lifecycle.MutableLiveData;

import com.example.mvvm_base.base.model.BaseRepo;
import com.example.mvvm_base.userbean.UserEntity;

import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;
import okhttp3.RequestBody;

public class LoginRepo extends BaseRepo {

    public void login(RequestBody body, MutableLiveData<UserEntity> success,MutableLiveData<String> failure){
        apiService.login(body)
              .subscribeOn(Schedulers.io())
              .observeOn(AndroidSchedulers.mainThread())
              .subscribe(new Observer<UserEntity>() {
                  @Override
                  public void onSubscribe(Disposable d) {

                  }

                  @Override
                  public void onNext(UserEntity userEntity) {
                   success.setValue(userEntity);
                  }

                  @Override
                  public void onError(Throwable e) {
                    failure.setValue(e.getMessage());
                  }

                  @Override
                  public void onComplete() {

                  }
              });
    }
}
